﻿/* CSharp project - 2nd chance
 * Autor: Neuza Figueira*/

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Project
{
    public partial class Form2 : Form
    {
        Database database;
        int yearIndex;
 
        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            this.database = new Database();
            this.database.openDatabase();
            this.comboBox1.Items.AddRange(this.database.getYears().ToArray());           
        }

        private int getComboBoxIndex()
        {
            return this.yearIndex = this.comboBox1.SelectedIndex;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int index = getComboBoxIndex();
            string yearString = this.database.getYears()[index];
            this.dataGridView1.DataSource = this.database.Statistic1(yearString);
            dataGridView1.Columns[0].Width = 100;
            dataGridView1.Columns[1].Width = 105;
            dataGridView1.ReadOnly = true;
        }
    }
}
